<?php
/**
*  +----------------------------------------------------------------------------------------------+
*   | Explain:新表修改后的新函数
*  +----------------------------------------------------------------------------------------------+
*   | Author: ONLY <491518132@qq.com>
*	+----------------------------------------------------------------------------------------------+
*   | Creater Time : 2013-10-24 	
*  +----------------------------------------------------------------------------------------------+
*   | Link :		http://www.phpyrb.com	     
*  +----------------------------------------------------------------------------------------------+
**/

	class Newpro {
		public function __construct(){
			
		}
		
		/**
		 * 返回供应商列表
		 * @param string $_status 状态
		 * @param string $_field 字段
		 * @return array $info
		 */
		function suppliers($_status = FALSE,$_field = 'id,name'){
			$model = M('ProductSuppliers');
			$where = array();
			$_status ? $where['status'] = 1 : false;
			$info = $model->field($_field)->where($where)->select();
			return $info;
	 	}
	 	
	 	/**
	 	 * 返回供应商下的产品ID
	 	 * @param int $_id 供应商的ID
	 	 * @return array $proids
	 	 */
	 	function supptopro($_id){
	 		$model = M('ProductToSuppliers');
	 		$where = array();
	 		$where['suppliers_id'] = $_id;
	 		$proids = $model->field('product_id')->where($where)->select();
// 	 		echo $model->getLastSql();
	 		$proids = $this->arr2to1($proids,'product_id');
	 		return $proids;
	 	}
	 	
	 	/**
	 	 * 返回产品的基本信息(ID,主分类，主图，名称，品牌，基价，状态，模型)
	 	 * @param array $_proids 产品ID
	 	 * @return array $proinfo
	 	 */
	 	function protobaseinfo($_proids){
	 		$model = M('product');
	 		$where = array();
	 		$where['id'] = is_array($_proids) ? array('IN',implode(',', $_proids)) : $_proids;
	 		$field = 'id,mname,brand_id,mian_cat,price,image,status,name,write_date';
	 		$proinfo = $model->field($field)->where($where)->select();
	 		return $proinfo;
	 	}
	 	
	 	function accomplish(){
	 		
	 	}
	 	
	 	function unfinished_order($_status = array('shipping_status' => 1),$_time = 604800){
	 		$model = M('Order');
	 		$where = array();
	 		foreach ($_status as $k => $v){
	 			$where[$k] = $v;
	 		}
	 		$where['shipping_time'] = array('GT',time() - $_time);
	 	}

	 	/**
	 	 * 根据产品ID返回产品所有价格、起批数、ID、创建时间
	 	 * @param array $_ids
	 	 * @return array $price
	 	 */
	 	function b2btoprice($_ids){
	 		$model = M('ProductPriceB2b');
	 		$where = array();
	 		$where['product_id'] = array('IN',implode(',', $_ids));
	 		$price = $model->where($where)->select();
// 	 		echo $model->getLastSql();
	 		$price = field2key($price,'product_id');
	 		return $price;
	 	}
	 	
	 	/**
	 	 * 根订单ID返回订单商品详情
	 	 * @param array $_orderid
	 	 * @return array $Info
	 	 */
	 	function b2b_order_goods($_orderid = 'all'){
	 		$model = M('OrderGoods');
	 		$where = array();
	 		$where['platfrom'] = 'SMW01';
	 		$_orderid == 'all' ? true : $where['order_id'] = is_array($_orderid) ? array("IN",implode(',', $_orderid)) : $_orderid;
	 		$info = $model->where($where)->select();
	 		// 		echo $model->getLastSql();
	 		return $info;
	 	}
	 	
	 	/**
	 	 * 
	 	 * @param unknown $_ids
	 	 * @return Ambigous <unknown, multitype:unknown >
	 	 */
	 	function b2btoxls($_proids){
	 		$model = M();
	 		$price = array();
	 		$temp = array();
	 		is_array($_proids) ? TRUE : exit('请传入数组！');
	 		$filed = " pb.product_id,pb.minsale,pb.price,pb.jiaer,pb.jiayi,pb.jialiu,pb.jiasan,pb.jiasi,pb.jiawu,pb.ctime,p.`status`,p.`name`,p.brand_id";
	 		$sql = "select $filed FROM product_price_b2b as pb LEFT JOIN product as p ON pb.product_id=p.id WHERE pb.product_id IN (".implode(',', $_proids).")";
	 		$temp = $model->query($sql);
// 	 		echo $model->getLastSql();
			$model = M('ProductBrand');
			$bid = $this->arr2to1($temp,'brand_id');
			$bid = array_unique($bid);
			$where['id'] = array('IN',implode(',', $bid));
			$brand = $model->where($where)->select();
			$brand = field2key($brand,'id');
			$attr = $this->produtct_attr($_proids, '货源');
			foreach ($temp as $k => $v){
				$price[$v['product_id']]['id'] = $v['product_id'];
				$price[$v['product_id']]['name'] = $v['name'];
				$price[$v['product_id']]['brand'] = $brand[$v['brand_id']]['name'];
				$price[$v['product_id']]['huoyuan'] = $attr[$v['product_id']]['value'];
				$price[$v['product_id']]['price'] = $v['price'] * 0.01;
				$price[$v['product_id']]['jiayi'] = $v['jiayi'] * 0.01;
				$price[$v['product_id']]['jiaer'] = $v['jiaer'] * 0.01;
				$price[$v['product_id']]['jiasan'] = $v['jiasan'] * 0.01;
				$price[$v['product_id']]['jiasi'] = $v['jiasi'] * 0.01;
				$price[$v['product_id']]['jiawu'] = $v['jiawu'] * 0.01;
				$price[$v['product_id']]['jialiu'] = $v['jialiu'] * 0.01;
				$price[$v['product_id']]['status'] = $v['status'];
				$price[$v['product_id']]['ctime'] = $v['ctime'];
			}
	 		return $price;
	 	}
	 	
	 	
	 	/**
	 	 * 根据模型名返回产品ID
	 	 * @param string $_modename 模型名
	 	 * @param string $_limit 条数
	 	 * @param string $_count 总数
	 	 * @param string | int $_status 上下架状态
	 	 * @return array $proids 
	 	 */
	 	function modetopro($_modename,$_limit = NULL,$_count = FALSE,$_status = FALSE){
	 		$model = M('Product');
	 		$where = array();
	 		$where['mname'] = $_modename;
	 		$_status ? $where['status'] = 1: FALSE;
	 		if($_count){
	 			$count = $model->where($where)->count('id');
	 			echo $model->getLastSql();
	 			return $count;
	 		}
	 		$proids = $model->field('id')->where($where)->limit($_limit)->select();
// 	 		echo $model->getLastSql();
// 	 		dump($proids);
	 		$proids = $this->arr2to1($proids);
// 	 		dump($proids);
	 		return $proids;
	 	}
	 	
	 	/**
	 	 * 返回属性组
	 	 * @return array
	 	 */
	 	function attrgroup(){
	 		$model = M('Attribute');
			$attr = $model->select();
			$attrgroup = array();
// 			dump($attr);
			foreach ($attr as $k => $v){
				if(! empty($attrgroup)){
					$attrgroup[$v['name']][] = $v;
				}else {
					$attrgroup[$v['name']][] = $v;
				}
			}
			return $attrgroup;		
	 	}
	 	
	 	/**
	 	 *获取关联的属性组及属性值
	 	 */
	 	function cattoattribute($cid=0,$platform='ALL',$status=1) {
	 		//获取关联的属性组
	 		$catdao=M('CategoryAttribute');
	 		$where=array();
	 		$where['category_id']=$cid;
	 		$platform=strtoupper($platform);
	 		if($platform!='ALL'){
	 			$platformstr=array();
	 			if(strpos($platform,',')!==false){
	 				$platforms=explode(',', $platform);
	 				foreach ($platforms as $v){
	 					$platformstr[]=' FIND_IN_SET('.$v.',`platform`)>0 ';
	 				}
	 				$platformstr=implode('OR', $platformstr);
	 			}else{
	 				$platformstr=' FIND_IN_SET('.$v.',`platform`)>0 ';
	 			}
	 			$where['_String']=$platformstr;
	 		}
	 		$res=$catdao->where($where)->order('sequence DESC')->select();
	 		if(empty($res)){
	 			return 0;
	 		}
	 		$aids=arr_to_explode($res,'attr_id',',');
	 		$attrdao=M('Attribute');
	 		$where=array();
	 		if($status!==false){
	 			$where['status']=$status;
	 		}
	 		$where['id']=array('IN',$aids);
	 		$attr=$attrdao->where($where)->select();
	 		if(empty($attr)){
	 			return 0;
	 		}
	 		return $attr;
	 	}//end cat_attr
	 	
	 	/**
	 	 * 返回产品的某个类别的属性值
	 	 * @param array $_proids
	 	 * @param string $_attrname 如 颜色，货源
	 	 * @return Ambigous <unknown, multitype:unknown >
	 	 */
	 	function produtct_attr($_proids,$_attrname){
	 		$model = M();
	 		$where = is_array($_proids) ? "p.product_id IN (".implode(',', $_proids).')' : 'p.product_id = '.$_proids;
	 		$where .= ' AND a.alias = '."'$_attrname'";
	 		$sql = "SELECT p.product_id,a.id,a.name,a.value FROM `product_attribute` p LEFT JOIN attribute a ON p.attribute_id = a.id WHERE $where ";
	 		$info = $model->query($sql);
// 	 		echo $model->getLastSql();
	 		return field2key($info,'product_id');
	 	}
	 	
	 	/**
	 	 * 返回产品的关联产品ID
	 	 * @param array $_ids
	 	 * @param string $_status
	 	 * @return array $relev
	 	 */
	 	function relevance($_ids,$_status = FALSE){
	 		$model = M('ProductRelated');
	 		$where = array();
	 		$where['from'] = is_array($_ids) ? array("IN",implode(',', $_ids)) : $_ids;
	 		$_status ? $where['status'] = $_status : FALSE;
	 		$relev = $model->field('to')->where($where)->select();
	 		$relev = $this->arr2to1($relev,'to');
	 		return $relev;
	 	}
	 	
	 	/**
	 	* 订单简单筛选
	 	* @param array $_where 
	 	* @param string $_limit 
	 	* @param string $_platform 
	 	* @return array $info
	 	* @author MaWei (http://www.phpyrb.com)
	 	* @date 2014-1-10下午3:52:47
	 	*/
	 	function order_check($_where = array(),$_limit = 'all' ,$_platform = 'SMW01'){
	 		$model = M("Order");
	 		$field = "o.id id,o.sn,o.userid,u.username,u.mobile,o.`status`,o.pay_status,o.shipping_status,o.add_time,o.amount,oa.consignee";
// 	 		if(! empty($_where)){
// 		 		foreach ($_where as $k => $v){
// 		 			if($k == 'add_time'){
// 		 				$t = explode(',', $v);
// 		 				$where .= " AND (o.".$k." >= ".array_shift($t)." and o.".$k." <= ".array_shift($t).")";
// 		 			}elseif ($k=='sn'){
// 		 				$where .= "  AND o.".$k." like '%".$v."%'";
// 		 			}elseif ($k=='userid'){
// 		 				$where .= "  AND o.".$k." = '".$v."'";
// 		 			}elseif ($k=='consignee'){
// 		 				$where .= "  AND oa.".$k." like '%".$v."%'";
// 		 			}else{
// 		 				$where .= "  AND u.".$k." LIKE '%".$v."%'";
// 		 			}
// 		 		}
// 	 		}
	 		if($_limit == 'all'){
	 			//$sql = "SELECT count(o.id) as num FROM `order` o JOIN `user` u ON o.userid=u.id JOIN order_address  oa ON o.id=oa.order_id WHERE o.platform='".$_platform."'".$where;
	 			
	 			//$info = $model->query($sql);
// 	 			echo $model->getLastSql();
	 			//$info = array_shift($info);
	 			//return $info['num'];
	 			$count = $model->join(" as o left join `user` as u on o.userid = u.id")->join(" order_address as oa on o.id = oa.order_id ")->where($_where)->count();
	 			return $count;
	 		}else {
	 			//$sql = "SELECT $filed  FROM `order` o JOIN `user` u ON o.userid=u.id JOIN order_address  oa ON o.id=oa.order_id WHERE o.platform='".$_platform."'".$where. ' ORDER BY o.id DESC LIMIT '.$_limit ;
	 			$res = $model->field($field)->join(" as o left join `user` as u on o.userid = u.id")->join(" order_address as oa on o.id = oa.order_id ")->order('o.id desc')->where($_where)->limit($_limit)->select();
	 		
	 		} 		
	 		//$info = $model->query($sql);
	 		return  $res;
	 	}
	 	
	 	
	 	
	 	/**
	 	 * 查找拆单的订单列表
	 	 * @param array $_where
	 	 * @param string $_limit
	 	 * @param string $_platform
	 	 * @return array $info
	 	 * @author tb (http://www.phpyrb.com)
	 	 * @date 2014-1-10下午3:52:47
	 	 */
	 	function order_check_separate($_where = array(),$separate=0,$_limit = 'all' ,$_platform = 'SMW01'){
	 		$model = M("Order");
	 		if($separate==1){
	 			$_where['oe.element'] = 'separate';
	 		}else{
	 			$_where['oe.element'] = 'reissue';
	 		}
	 		
	 		$field = "o.id id,o.sn,o.userid,u.username,u.mobile,o.`status`,o.pay_status,o.shipping_status,o.add_time,o.amount,oa.consignee"; 		
	 		if($_limit == 'all'){ 		
	 			$count = $model->join(" as o left join `user` as u on o.userid = u.id")->join(" order_ext as oe on o.id = oe.order_id")->join(" order_address as oa on o.id = oa.order_id ")->where($_where)->count();
	 			return $count;
	 		}else {	 			
	 			$res = $model->field($field)->join(" as o left join `user` as u on o.userid = u.id")->join(" order_ext as oe on o.id = oe.order_id")->join(" order_address as oa on o.id = oa.order_id ")->order('o.id desc')->where($_where)->limit($_limit)->select();
	 		}
	 		return  $res;
	 	}
	 	
	 	
	 	/**
	 	* 根据订单ID返回详细信息
	 	* @param  array $_ids 订单ID
	 	* @param  string $_platform 平台
	 	* @param  string $_field 字段
	 	* @return array $info
	 	* @author MaWei (http://www.phpyrb.com)
	 	* @date 2014-2-13  下午6:09:43
	 	*/
	 	function orderinfo ($_ids,$_platform = FALSE,$_field = '*'){
	 		$model = M('Order');
	 		$where = array();
	 		$where['id'] = is_array($_ids) ? array('IN',implode(',', $_ids)) : $_ids;
	 		$_platform ? $where['platfrom'] = $_platform : false;
	 		$info = $model->field($_field)->where($where)->select();
// 	 		echo $model->getLastSql();
	 		return $info;
	 	}
	 	
	 	/**
	 	* pv、mv列表
	 	* @param  string $_limit 分页，不传为总条数
	 	* @param  int $id ID
	 	* @param  int $userid 用户ID
	 	* @return array $info
	 	* @author MaWei (http://www.phpyrb.com)
	 	* @date 2014-2-13  下午2:55:17
	 	*/
	 	function pvmvlist($_limit = NULL,$_id = FALSE,$_userid = FALSE){
	 		$model = M('OrderFinance');
	 		$where = array();
	 		if($_id){
	 			$where['id'] = $_id;
	 			$info = $model->where($where)->find();
	 			return $info;
	 		}
	 		$where['_string'] = "subject = 'PV' OR subject = 'MV'";
	 		$_userid ? $where['userid'] = $_userid : FALSE;
	 		if(empty($_limit)){
	 			$count = $model->where($where)->count();
	 			return $count;
	 		}
	 		$info = $model->where($where)->order('id DESC')->limit($_limit)->select();
	 		return $info;
	 	}
	 	
	 	
	 	/**
	 	* pv、mv显示列表
	 	* @param  string $_limit 分页
	 	* @param  string $_ordersn 订单序列号
	 	* @return array $info 
	 	* @author MaWei (http://www.phpyrb.com)
	 	* @date 2014-2-14  下午2:24:14
	 	*/
	 	function pvmvinfo($_limit = NULL,$map = array()){
	 		$dao = M("Order");
	 		$map['f.subject'] = array('In','PV','MV');
	 		$field = 'f.id id,o.id order_id,f.`subject`,f.`value`,f.`status`,f.userid,f.platform,o.sn,o.`status` ostatus';	 	
	 		if(empty($_limit)){
	 			$count = $dao->join(" as o left join order_finance as f on f.order_id = o.id ")->where($map)->count();
	 			
	 			return $count;
	 		}
	 		$info = $dao->field($field)->join(" as o left join order_finance as f on f.order_id = o.id ")->where($map)->limit($_limit)->select();
	 		return $info;
	 	}
	 	
	 	/**
	 	* 返回用户余额
	 	* @param  int $_userid 
	 	* @param  srting $_subject 科目 
	 	* @param  srting $_platform 平台
	 	* @return array $info
	 	* @author MaWei (http://www.phpyrb.com)
	 	* @date 2014-2-13  下午5:08:36
	 	*/
	 	function balance($_userid,$_subject = NULL,$_platform = NULL){
	 		$model = M('UserMoney');
	 		$where = array();
	 		$where['userid'] = $_userid;
	 		$_subject ? $where['subject'] = $_subject : FALSE;
	 		$_subject ? $where['platfrom'] = $_platform : FALSE;
	 		$info = $model->where($where)->select();
	 		return $info;
	 	}
	 	
	 	/**
	 	 * 二维数组返回一维或字符串
	 	 * @param array $_arr
	 	 * @param string $_field
	 	 * @param string $_type 1为数组 2为字符串
	 	 * @return multitype:array|multitype:string
	 	 */
	 	function arr2to1($_arr,$_field = 'id',$_type = '1'){
	 		if ( ! $_arr ) return array();
	 		$arrayids = array();
	 		foreach ($_arr as $k => $v){
	 			if(is_array($v[$_field])){
	 				foreach ($v[$_field] as $key => $val){
	 					$arrayids[] = $val[$_field];
	 				}
	 			}else{
	 				$arrayids[] = $v[$_field];
	 			}
	 		}
	 		if($_type != '1') $arrayids = implode(',',$arrayids);
	 	
	 		return $arrayids;
	 	}
	 	
	 	/**
	 	 * 返回二维数组里面元素的交集
	 	 * @param array $_arr 二维数组
	 	 * @return $value 返回二维数组里面元素的交集
	 	 */
	 	function intersection($_arr) {
	 		$value = array();
	 		$init = true;
	 		if(count($_arr) == '1'){
	 			return array_shift($_arr);
	 		}else{
	 			foreach ($_arr as $k => $v){
	 				if(empty($value) && $init){
	 					$value = $v;
	 				}else{
	 					$value = array_intersect($value,$v);
	 					$init = false;
	 				}
	 			}
	 			return $value;
	 		}
	 	}
	 	
	 	/**
	 	* 把导入的Exelc 返回成数组
	 	* @param file $file 
	 	* @param int $start_row 
	 	* @param int $Sheet 
	 	* @return array $info
	 	* @author MaWei (http://www.phpyrb.com)
	 	* @date 2014-1-9下午3:23:09
	 	*/
	 	function read_xls($file='',$start_row=2,$Sheet=0) {
	 		//读取并分析exce
	 		if (! file_exists ( $file )) {
	 			return '-'.__LINE__;
	 		}
	 		import("@.Com.PHPExcel",'','.php');
	 		//import("@.Com.PHPExcel.IOFactory",'','.php');
	 		import("@.Com.PHPExcel.Reader.Excel5", '','.php');
	 		import("@.Com.PHPExcel.Reader.Excel2007",'','.php');
	 		$PHPExcel = new PHPExcel ();
	 		$PHPReader = new PHPExcel_Reader_Excel2007 ();
	 		if (! $PHPReader->canRead ( $file )) {
	 			$PHPReader = new PHPExcel_Reader_Excel5 ();
	 			if (! $PHPReader->canRead ( $file )) {
	 				return '-'.__LINE__;
	 			}
	 		}
	 		$objPHPExcel = $PHPReader->load ( $file );
	 		$sheet = $objPHPExcel->getSheet ($Sheet); // 读取第一個工作表(编号从 0 开始)
	 		//$sheet = $objPHPExcel->getSheetByName ( $sheet ); // 读取第一個工作表(编号从 0 开始)
	 		$highestRow = $sheet->getHighestRow (); // 取得总行数
	 		$highestColumn = $sheet->getHighestColumn (); // 取得总列数
	 		$arr = array (
	 				1 => 'A',2 => 'B',3 => 'C',4 => 'D',
	 				5 => 'E',6 => 'F',7 => 'G',8 => 'H',9 => 'I',10 => 'J',11 => 'K',12 => 'L',
	 				13 => 'M',14 => 'N',15 => 'O',16 => 'P',17 => 'Q',18 => 'R',19 => 'S',20 => 'T',
	 				21 => 'U',22 => 'V',23 => 'W',24 => 'X',25 => 'Y',26 => 'Z');
	 		$column = array_search ( $highestColumn, $arr );
	 		//读取表中的数据
	 		$data = array ();
	 		for($x = $start_row; $x <= $highestRow + 1; $x ++) {
	 			for($i=0;$i<=15;$i++){
	 				$row = '';
	 				$row = $sheet->getCellByColumnAndRow ( $i, $x )->getValue ();
	 				$data[$x][$i]=trim($row);//不使用trim有可能获取到的是一个对象
	 			}
	 		}
	 		return $data;
	 	}//end read_xls
	 	
	 	
	 	/**
	 	 *
	 	 * @param unknown $_proinfo
	 	 */
	 	function out_xls($_proinfo){
	 		import ( "@.Com.PHPExcel", '', '.php' );
	 		// import("@.Com.PHPExcel.IOFactory",'','.php');
	 		import ( "@.Com.PHPExcel.Writer.Excel5", '', '.php' );
	 		// import("@.ORG.PHPExcel.Writer.Excel2007",'','.php');
	 		// 创建一个处理对象实例
	 		$objExcel = new PHPExcel ();
	 	
	 		// 创建文件格式写入对象实例, uncomment
	 		$objWriter = new PHPExcel_Writer_Excel5 ( $objExcel ); // 用于其他版本格式
	 		// or
	 		// $objWriter = new PHPExcel_Writer_Excel2007($objExcel); // 用于 2007 格式
	 		// $objWriter->setOffice2003Compatibility(true);
	 	
	 		// 设置文档基本属性
	 		$objProps = $objExcel->getProperties ();
	 		$objProps->setCreator ( "Zeal Li" );
	 		$objProps->setLastModifiedBy ( "Zeal Li" );
	 		$objProps->setTitle ( "Office XLS Test Document" );
	 		$objProps->setSubject ( "Office XLS Test Document, Demo" );
	 		$objProps->setDescription ( "Test document, generated by PHPExcel." );
	 		$objProps->setKeywords ( "office excel PHPExcel" );
	 		$objProps->setCategory ( "Test" );
	 		// 设置当前的sheet索引，用于后续的内容操作。
	 		// 一般只有在使用多个sheet的时候才需要显示调用。
	 		// 缺省情况下，PHPExcel会自动创建第一个sheet被设置SheetIndex=0
	 		$objExcel->setActiveSheetIndex ( 0 );
	 		$objActSheet = $objExcel->getActiveSheet ();
	 		
	 		// 设置当前活动sheet的名称
	 		$day = date ( 'Y-m-d' );
	 		$objActSheet->setTitle ( '云采购_' . $day );
	 		// 设置单元格样式
	 		// 设置宽度
	 		// $objActSheet->getColumnDimension('B')->setAutoSize(true);
	 		$objActSheet->getColumnDimension ( 'A' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'B' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'C' )->setWidth ( 45 );
	 		$objActSheet->getColumnDimension ( 'D' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'E' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'F' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'G' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'H' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'I' )->setWidth ( 5 );
	 		$objActSheet->getColumnDimension ( 'J' )->setWidth ( 18 );
	 		$objActSheet->getColumnDimension ( 'K' )->setWidth ( 5 );
	 		$objActSheet->getColumnDimension ( 'L' )->setWidth ( 5 );
	 		$objActSheet->getColumnDimension ( 'M' )->setWidth ( 5 );
	 		$objActSheet->getColumnDimension ( 'N' )->setWidth ( 5 );
	 		$objActSheet->getColumnDimension ( 'O' )->setWidth ( 5 );
	 		$objActSheet->getColumnDimension ( 'P' )->setWidth ( 5 );
	 	
	 		$objActSheet->getRowDimension ( '1' )->setRowHeight ( 10 );
	 		$objActSheet->getRowDimension ( '2' )->setRowHeight ( 50 );
	 		$objActSheet->getRowDimension ( '8' )->setRowHeight ( 45 );
	 	
	 		$objActSheet->setCellValue ( 'A2', 'ID' );
	 		$objActSheet->setCellValue ( 'B2', '品牌' );
	 		$objActSheet->setCellValue ( 'C2', '名称' );
	 		$objActSheet->setCellValue ( 'D2', '货源' );
	 		$objActSheet->setCellValue ( 'E2', '云购商户' );
	 		$objActSheet->setCellValue ( 'F2', '全国' );
	 		$objActSheet->setCellValue ( 'G2', '省级' );
	 		$objActSheet->setCellValue ( 'H2', '市级' );
	 		$objActSheet->setCellValue ( 'I2', '更新' );
	 		$objActSheet->setCellValue ( 'J2', '更新时间' );
	 		$objActSheet->setCellValue ( 'K2', '基价' );
	 		$objActSheet->setCellValue ( 'L2', '加价' );
	 		$objActSheet->setCellValue ( 'M2', '加级' );
	 		$objActSheet->setCellValue ( 'N2', '更新' );
	 		$objActSheet->setCellValue ( 'O2', '删除' );
	 		$objActSheet->setCellValue ( 'P2', '上架' );
	 		$order_count = count ( $cart );
	 		$dl = $cart;
	 		$i = 3;
	 		$i < $order_count + 3;
	 		foreach ( $_proinfo as $k => $v ) {
	 			$x = $i - 2;
	 			$pinpai = $steall [$v ['sbjipnpl']] ['title'];
	 			$huoyuan = $steall [$v ['hoyr']] ['title'];
	 			$objActSheet->getRowDimension ( $i )->setRowHeight ( 30 );
	 			$objActSheet->setCellValue ( 'A' . $i, $v ['id'] );
	 			$objActSheet->setCellValue ( 'B' . $i, $v['brand'] );
	 			$objActSheet->setCellValue ( 'C' . $i, $v ['name'] );
	 			$objActSheet->setCellValue ( 'D' . $i, $v['huoyuan'] );
	 			$objActSheet->setCellValue ( 'E' . $i, $v ['jiayi'] );
	 			$objActSheet->setCellValue ( 'F' . $i, $v ['jiaer'] );
	 			$objActSheet->setCellValue ( 'G' . $i, $v ['jiasan'] );
	 			$objActSheet->setCellValue ( 'H' . $i, $v ['jiasi'] );
	 			$objActSheet->setCellValue ( 'I' . $i, '0' );
	 			$objActSheet->setCellValue ( 'J' . $i, date ( 'Y-m-d', $v ['ctime'] ) );
	 			$objActSheet->setCellValue ( 'K' . $i, $v ['price'] );
	 			$objActSheet->setCellValue ( 'L' . $i, $v ['jiawu'] );
	 			$objActSheet->setCellValue ( 'M' . $i, $v ['jialiu'] );
	 			$objActSheet->setCellValue ( 'N' . $i, '0' );
	 			$objActSheet->setCellValue ( 'O' . $i, 0 );
	 			$objActSheet->setCellValue ( 'P' . $i, $v ['status'] );
	 			$i ++;
	 		}
	 		// 保护单元格
	 		// $objExcel->getSheet(1)->getProtection()->setSheet(true);
	 		// $objExcel->getSheet(1)->protectCells('A1:G'.'$i', 'PHPExcel');
	 	
	 		// 输出内容
	 		$temp = array_shift($_proinfo);
	 		$brand = $temp['brand'];
	 		$outputFileName = date ( 'Y_m_d_H_m_s' ). ".xls";
	 		$outputFileName = iconv ( "UTF-8", "GB2312//TRANSLIT", $outputFileName );
	 		
	 		// 设置附件下载目录
	 		$path = date ( 'Y-m' ) . '/';
	 		$path = './Downloads/' . $path;
	 		if(! file_exists( $path)){
	 			if(! mkdir ( $path)){
	 				echo '创建文件夹失败！';
	 				exit;
	 			}
	 		}
	 		
	 		// 到文件
	 		$objWriter->save($path.$outputFileName);
	 		
	 		
	 		$pathinfo = array();
	 		$pathinfo['path'] = $path;
	 		$pathinfo['name'] = $outputFileName;
	 		return $pathinfo;
// 	 		echo "<a href=" 
	 		// or
	 		// 到浏览器
	 		/* header ( "Content-Type: application/force-download" );
	 		header ( "Content-Type: application/octet-stream" );
	 		header ( "Content-Type: application/download" );
	 		header ( 'Content-Disposition:inline;filename="' . $outputFileName . '"' );
	 		header ( "Content-Transfer-Encoding: binary" );
	 		header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" );
	 		header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
	 		header ( "Pragma: no-cache" );
	 		$objWriter->save ( 'php://output' ); */
	 	}
	 	
	 	/**
	 	* 送货单导出
	 	* @param array $_info 商品信息 
	 	* @return return_type
	 	* @author MaWei (http://www.phpyrb.com)
	 	* @date 2014-1-9上午11:43:36
	 	*/
	 	function goods_xls($_info){
	 		import ( "@.Com.PHPExcel", '', '.php' );
	 		// import("@.Com.PHPExcel.IOFactory",'','.php');
	 		import ( "@.Com.PHPExcel.Writer.Excel5", '', '.php' );
	 		// import("@.ORG.PHPExcel.Writer.Excel2007",'','.php');
	 		// 创建一个处理对象实例
	 		$objExcel = new PHPExcel ();
	 		 
	 		// 创建文件格式写入对象实例, uncomment
	 		$objWriter = new PHPExcel_Writer_Excel5 ( $objExcel ); // 用于其他版本格式
	 		// or
	 		// $objWriter = new PHPExcel_Writer_Excel2007($objExcel); // 用于 2007 格式
	 		// $objWriter->setOffice2003Compatibility(true);
	 		 
	 		// 设置文档基本属性
	 		$objProps = $objExcel->getProperties ();
	 		$objProps->setCreator ( "Zeal Li" );
	 		$objProps->setLastModifiedBy ( "Zeal Li" );
	 		$objProps->setTitle ( "Office XLS Test Document" );
	 		$objProps->setSubject ( "Office XLS Test Document, Demo" );
	 		$objProps->setDescription ( "Test document, generated by PHPExcel." );
	 		$objProps->setKeywords ( "office excel PHPExcel" );
	 		$objProps->setCategory ( "Test" );
	 		// 设置当前的sheet索引，用于后续的内容操作。
	 		// 一般只有在使用多个sheet的时候才需要显示调用。
	 		// 缺省情况下，PHPExcel会自动创建第一个sheet被设置SheetIndex=0
	 		$objExcel->setActiveSheetIndex ( 0 );
	 		$objActSheet = $objExcel->getActiveSheet ();
	 	
	 		// 设置当前活动sheet的名称
	 		$day = date ( 'Y-m-d H-m-s' );
	 		$objActSheet->setTitle ( '送贷单_' . $day );
	 		// 设置单元格样式
	 		// 设置宽度
	 		// $objActSheet->getColumnDimension('B')->setAutoSize(true);
	 		$objActSheet->getColumnDimension ( 'A' )->setWidth ( 12 );
	 		$objActSheet->getColumnDimension ( 'B' )->setWidth ( 55 );
	 		$objActSheet->getColumnDimension ( 'C' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'D' )->setWidth ( 6 );
	 		$objActSheet->getColumnDimension ( 'E' )->setWidth ( 6 );
	 		 
	 		$objActSheet->setCellValue ( 'A2', 'ID' );
	 		$objActSheet->setCellValue ( 'B2', '商品名称' );
	 		$objActSheet->setCellValue ( 'C2', '单价' );
	 		$objActSheet->setCellValue ( 'D2', '数量' );
	 		$objActSheet->setCellValue ( 'E2', '总价' );
	 		$i = 3;
	 		foreach ( $_info as $k => $v ) {
	 			$objActSheet->getRowDimension ( $i )->setRowHeight ( 30 );
	 			$objActSheet->setCellValue ( 'A' . $i, $v ['id'] );
	 			$objActSheet->setCellValue ( 'B' . $i, $v['name'] );
	 			$objActSheet->setCellValue ( 'C' . $i, $v ['price'] );
	 			$objActSheet->setCellValue ( 'D' . $i, $v['number'] );
	 			$objActSheet->setCellValue ( 'E' . $i, $v ['count'] );
	 			$i ++;
	 		}
	 		// 保护单元格
	 		// $objExcel->getSheet(1)->getProtection()->setSheet(true);
	 		// $objExcel->getSheet(1)->protectCells('A1:G'.'$i', 'PHPExcel');
	 		 
	 		// 输出内容
	 		$outputFileName = date ( 'Y_m_d_H_m_s' ). ".xls";
	 		$outputFileName = iconv ( "UTF-8", "GB2312//TRANSLIT", $outputFileName );
	 	
	 		// 设置附件下载目录
	 		$path = date ( 'Y-m' ) . '/';
	 		$path = './Downloads/' . $path;
	 		if(! file_exists( $path)){
	 			if(! mkdir ( $path)){
	 				echo '创建文件夹失败！';
	 				exit;
	 			}
	 		}
	 	
	 		// 到文件
	 		$pathinfo = $path.$outputFileName;
	 		$objWriter->save($pathinfo);
	 		return $pathinfo;
	 	}
	 	
	 	
	 	/**
	 	 * 消费金额
	 	 * @param array $_info 商品信息
	 	 * @return return_type
	 	 * @author MaWei (http://www.phpyrb.com)
	 	 * @date 2014-1-9上午11:43:36
	 	 */
	 	function xfprint_xls($_info){
	 		import ( "@.Com.PHPExcel", '', '.php' );
	 		// import("@.Com.PHPExcel.IOFactory",'','.php');
	 		import ( "@.Com.PHPExcel.Writer.Excel5", '', '.php' );
	 		// import("@.ORG.PHPExcel.Writer.Excel2007",'','.php');
	 		// 创建一个处理对象实例
	 		$objExcel = new PHPExcel ();
	 			
	 		// 创建文件格式写入对象实例, uncomment
	 		$objWriter = new PHPExcel_Writer_Excel5 ( $objExcel ); // 用于其他版本格式
	 		// or
	 		// $objWriter = new PHPExcel_Writer_Excel2007($objExcel); // 用于 2007 格式
	 		// $objWriter->setOffice2003Compatibility(true);
	 			
	 		// 设置文档基本属性
	 		$objProps = $objExcel->getProperties ();
	 		$objProps->setCreator ( "Zeal Li" );
	 		$objProps->setLastModifiedBy ( "Zeal Li" );
	 		$objProps->setTitle ( "Office XLS Test Document" );
	 		$objProps->setSubject ( "Office XLS Test Document, Demo" );
	 		$objProps->setDescription ( "Test document, generated by PHPExcel." );
	 		$objProps->setKeywords ( "office excel PHPExcel" );
	 		$objProps->setCategory ( "Test" );
	 		// 设置当前的sheet索引，用于后续的内容操作。
	 		// 一般只有在使用多个sheet的时候才需要显示调用。
	 		// 缺省情况下，PHPExcel会自动创建第一个sheet被设置SheetIndex=0
	 		$objExcel->setActiveSheetIndex ( 0 );
	 		$objActSheet = $objExcel->getActiveSheet ();
	 		 
	 		// 设置当前活动sheet的名称
	 		$day = date ( 'Y-m-d H-m-s' );
	 		$objActSheet->setTitle ( '送贷单_' . $day );
	 		// 设置单元格样式
	 		// 设置宽度
	 		// $objActSheet->getColumnDimension('B')->setAutoSize(true);
	 		$objActSheet->getColumnDimension ( 'A' )->setWidth ( 15 );
	 		$objActSheet->getColumnDimension ( 'B' )->setWidth ( 20 );
	 		$objActSheet->getColumnDimension ( 'C' )->setWidth ( 15 );
	 		$objActSheet->getColumnDimension ( 'D' )->setWidth ( 15 );
	 		$objActSheet->getColumnDimension ( 'E' )->setWidth ( 15 );
	 		$objActSheet->getColumnDimension ( 'F' )->setWidth ( 25 );
	 		$objActSheet->getColumnDimension ( 'G' )->setWidth ( 20 );
	 		$objActSheet->getColumnDimension ( 'H' )->setWidth ( 15 );
	 		$objActSheet->getColumnDimension ( 'I' )->setWidth ( 15 );
	 		$objActSheet->getColumnDimension ( 'G' )->setWidth ( 10 );
	 		$objActSheet->getColumnDimension ( 'K' )->setWidth ( 55 );
	 			
	 		$objActSheet->setCellValue ( 'A2', '用户ID' );
	 		$objActSheet->setCellValue ( 'B2', '消费时间' );
	 		$objActSheet->setCellValue ( 'C2', '账号' );
	 		$objActSheet->setCellValue ( 'D2', '名称' );
	 		$objActSheet->setCellValue ( 'E2', '消费金额' );
	 		
	 		$objActSheet->setCellValue ( 'F2', '邮箱' );
	 		$objActSheet->setCellValue ( 'G2', '店名' );
	 		$objActSheet->setCellValue ( 'H2', '电话' );
	 		$objActSheet->setCellValue ( 'I2', '手机' );
	 		$objActSheet->setCellValue ( 'G2', '性别' );
	 		$objActSheet->setCellValue ( 'K2', '地址' );
	 		$i = 3;
	 		foreach ( $_info as $k => $v ) {
	 			$objActSheet->getRowDimension ( $i )->setRowHeight ( 30 );
	 			$objActSheet->setCellValue ( 'A' . $i, $v ['userid'] );
	 			$objActSheet->setCellValue ( 'B' . $i, $v['pay_time'] );
	 			$objActSheet->setCellValue ( 'C' . $i, $v ['username'] );
	 			$objActSheet->setCellValue ( 'D' . $i, $v['relname'] );
	 			$objActSheet->setCellValue ( 'E' . $i, $v ['amount'] );
	 			$objActSheet->setCellValue ( 'F' . $i, $v ['email'] );
	 			$objActSheet->setCellValue ( 'G' . $i, $v['company'] );
	 			$objActSheet->setCellValue ( 'H' . $i, $v ['tel'] );
	 			$objActSheet->setCellValue ( 'I' . $i, $v['mobile'] );
	 			$objActSheet->setCellValue ( 'G' . $i, $v['sex'] );
	 			$objActSheet->setCellValue ( 'K' . $i, $v ['address'] ); 			
	 			$i ++;
	 		}
	 		// 保护单元格
	 		// $objExcel->getSheet(1)->getProtection()->setSheet(true);
	 		// $objExcel->getSheet(1)->protectCells('A1:G'.'$i', 'PHPExcel');
	 			
	 		// 输出内容
	 		$outputFileName = 'xf'.date ( 'Y_m_d_H_m_s' ). ".xls";
	 		$outputFileName = iconv ( "UTF-8", "GB2312//TRANSLIT", $outputFileName );
	 		 
	 		// 设置附件下载目录
	 		$path = date ( 'Y-m' ) . '/';
	 		$path = './Downloads/' . $path;
	 		if(! file_exists( $path)){
	 			if(! mkdir ( $path)){
	 				echo '创建文件夹失败！';
	 				exit;
	 			}
	 		}
	 		 
	 		// 到文件
	 		$pathinfo = $path.$outputFileName;
	 		$objWriter->save($pathinfo);
	 		return $pathinfo;
	 	}
	 	
	 	
	 	/**
	 	 * 文件下载
	 	 * @param $_path $_name
	 	 * @return
	 	 */
	 	public function downloads($_path,$_name){
	 		if (!file_exists($_path)){
	 			header("Content-type: text/html; charset=utf-8");
	 			echo "File not found!";
	 			exit;
	 		} else {
	 			$file = fopen($_path.$_name,"r");
	 			Header("Content-type: application/octet-stream");
// 	 			header("Content-type:application/vnd.ms-excel");
	 			Header("Accept-Ranges: bytes");
	 			Header("Accept-Length: ".filesize($_path.$_name));
	 			Header("Content-Disposition: attachment; filename=$_name");
	 			echo fread($file, filesize($_path.$_name));
	 			fclose($file);
	 		}
	 	}
	}